# -*- coding: utf-8 -*-
"""
@Time : 2023/6/10 20:14
@Author : Gremore
@File : config
@Des: 
"""

import os


#fastapi 启动配置文件
class Config(object):
    """配置类"""
    #数据库连接信息
    HOST = "127.0.0.1"
    PORT = "3306"
    PWD = "123456"
    USER = "root"
    DBNAME = "tsim_db"
    PRO = False  #文档

    # 数据库配置
    SQLALCHEMY_DATABASE_URI: str = f"mysql+pymysql://{USER}:{PWD}@{HOST}:{PORT}/{DBNAME}"


class Text(object):
    """描述配置"""
    TITLE = "Tsimore 时序智能模型"
    VERSION = "v1.0"
    DESCRIPTION = "欢迎来到 Tsimore 时序智能模型"
    REDOC = None if Config.PRO else "/redoc"
    DOC = None if Config.PRO else "/docs"
    OPENAPI = None if Config.PRO else "/openapi.json"


class FilePath(object):
    SETS_PATH = os.path.dirname(os.path.abspath(__file__)) # settings目录
    COM_path = os.path.dirname(os.path.abspath(SETS_PATH)) # commons目录
    APP_PATH = os.path.dirname(os.path.abspath(COM_path)) # tsim 路径
    # BASE_DIR = os.path.dirname(os.path.abspath(APP_PATH)) # 后端服务项目目录

    LOG_FILE_PATH = os.path.join(APP_PATH, "logs") # 日志文件路径
    if not os.path.isdir(LOG_FILE_PATH):
        os.mkdir(LOG_FILE_PATH)

    APP_SERVER = os.path.join(LOG_FILE_PATH, 'server.log')
    APP_ERROR = os.path.join(LOG_FILE_PATH, 'error.log')
    CRUD_PATH = os.path.join(APP_PATH, "crud")  # curd路径


HTTP_MSG_MAP = {
    404: '请求路径找不到',
    405: '请求方法不支持',
    408: '请求超时',
    500: '服务器内部错误',
    302: '请求方法不支持'
}

API_WHITE_LIST = [
    '/docs',
    '/static',
    '/favicon.ico',
    '/openapi.json',
    '/redoc',
    '/api/user/register',
    '/api/user/login',
    # '/api/cases/out',
    # '/api/cases/rpc/',
    # '/api/project/gitSync'
]

API_ADMIN_LIST = [
    '/api/user/update'
]

API_LEADER_LIST = [
    '/api/project/insert'
]


# 项目日志滚动配置（日志文件超过10 MB就自动新建文件扩充）
LOGGING_ROTATION = "10 MB"


# 项目日志配置
LOGGING_CONF = {
    'server_handler': {
        'file': FilePath.APP_SERVER,
        'level': 'INFO',
        'rotation': LOGGING_ROTATION,
        'enqueue': True,
        'backtrace': False,
        'diagnose': False
    },
    'error_handler': {
        'file': FilePath.APP_ERROR,
        'level': 'ERROR',
        'rotation': LOGGING_ROTATION,
        'enqueue': True,
        'backtrace': True,
        'diagnose': True
    },
}
print(LOGGING_CONF)
